package com.lagou.listener;

import com.lagou.dao.PayDAO;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author: lcz
 * @date: Created in 13:01 2021/2/24
 * @description:
 */
@Component
public class BizListener {
    @Autowired
    private PayDAO payDAO;

    @RabbitListener(queues = "q.pay.dlx")
    public void getMessage(@Payload String bizId) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = simpleDateFormat.format(new Date());
        System.out.println("接收消息，time：" + time + "，bizId：" + bizId);
        if (payDAO.exists(bizId)) {
            System.out.println("订单超时了" + bizId);
            //记录超时的订单
            payDAO.setBizByTimeout(bizId);
            return;
        }
    }
}
